package com.superzqb.asus.superzqbUtil;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.superzqb.asus.superzqb.R;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by asus on 2017/4/19.
 */

public class GenCommentsAdapter extends BaseAdapter {
    private ArrayList<Map<String,Object>> items;
    private Context context;
    public  GenCommentsAdapter(Context context, ArrayList<Map<String, Object>> lists){
        this.context=context;
        this.items=lists;
    }
    @Override
    public int getCount() {
        return items==null?0:items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void setList(ArrayList<Map<String, Object>> list){
        this.items=list;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.comments_item,parent,false);
            convertView.setTag(new GenCommentsAdapter.ViewHolder(convertView));
        }
        GenCommentsAdapter.ViewHolder holder=(GenCommentsAdapter.ViewHolder) convertView.getTag();
        Map<String,Object> map=items.get(position);
        holder.user.setText(map.get("user").toString());
        holder.time.setText(map.get("time").toString());
        holder.content.setText(map.get("content").toString());
        return convertView;
    }


    class ViewHolder{
        private TextView user,time,content;
        public ViewHolder(View view){
            user=(TextView)view.findViewById(R.id.user);
            content=(TextView)view.findViewById(R.id.content);
            time=(TextView)view.findViewById(R.id.time);

        }
    }
}
